package Leetcode;
//给定一个整数 n，计算所有小于等于 n 的非负整数中数字 1 出现的个数。

import java.util.Scanner;

public class question001 {
    public static void main(String[] args) {
        Solution001 solution = new Solution001();
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        System.out.println(solution.countDigitOne(n));
    }
}
class Solution001 {
    public int countDigitOne(int n) {
        int sum = 0;
        if(n>=0){
            for (int i = n; i > 0; i--) {
                int count = 0;
                while(i>=1) {//判断整数的位数
                    i/=10;
                    count++;
                }
                String str = Integer.toString(i);
                for (int j = 0; j < count; j++) {
                    if(str.charAt(j) == '1'){
                        sum ++;
                    }
                }
            }
        }
        return sum;
    }
}
/*class Solution {
    public int countDigitOne(int n) {
        return CountProblem(n, 1);
    }

    public int CountProblem(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i; j > 0; j /= 10) {
                if (j % 10 == x) ++cnt;
            }
        }
        return cnt;
    }
}
 */